﻿<%@ WebHandler Language="C#" Class="GetData" %>

using System;
using System.Web;

public class GetData : IHttpHandler
{
    private string fundcodes = string.Empty;
    public StringOper sop = new StringOper();
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";

        if (!string.IsNullOrEmpty(context.Request["codes"]))
        {
            fundcodes = context.Request["codes"].Replace("_", ",");
            if (fundcodes.EndsWith(","))
            {
                fundcodes = fundcodes.Substring(0, fundcodes.Length - 1);
            }
            if (fundcodes.StartsWith(","))
            {
                fundcodes = fundcodes.Substring(1);
            }
            var netValues = GetFavFundsNetValueReport(fundcodes);
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            for (int i = 0; i < netValues.Count; i++)
            {

                sb.Append("<tr bgcolor=\"" + sop.changeStyle(i, "#f4f4f4", "#FFFFFF") + "\">");
                sb.Append("<td height=\"25\" align=\"center\">");
                sb.Append(i + 1);
                sb.Append("</td>");
                sb.Append("<td height=\"25\" align=\"center\">");
                sb.Append("<a href=\"" + PubBean.getFundZS(netValues[i].FundCode.Code, 2) + "\">");
                sb.Append(netValues[i].FundCode.Code + "</a>");
                sb.Append("</td>");
                sb.Append("<td align=\"center\">");
                sb.Append("<a href=\"" + PubBean.getFundZS(netValues[i].FundCode.Code, 2) + "\">");
                sb.Append("" + netValues[i].FundCode.SimpleName + "</a>");
                sb.Append("</td>");
                sb.Append("<td align=\"center\">");
                sb.Append("" + netValues[i].Releasetime.ToString("yyyy-MM-dd") + "");
                sb.Append("</td>");
                sb.Append("<td align=\"right\" style=\"padding-right: 10px;\">");
                if (netValues[i].FundCode.InvestType == 3)
                {
                    sb.Append(netValues[i].Perbonus.ToString("0.0000"));
                }
                else
                {
                    sb.Append(netValues[i].Newvalue.ToString("0.0000"));
                }

                sb.Append("</td>");
                sb.Append("<td align=\"right\" style=\"padding-right: 10px;\">");
                if (netValues[i].FundCode.InvestType == 3)
                {
                    sb.Append(netValues[i].Getradio.ToString("0.0000"));
                }
                else
                {
                    sb.Append(netValues[i].Allvalue.ToString("0.0000"));
                }
                sb.Append("</td><td align=\"right\" style=\"padding-right: 10px;\">");
                if (netValues[i].FundCode.InvestType == 3)
                {
                    sb.Append("-");
                }
                else
                {
                    sb.Append(sop.getUpdownStyle(netValues[i].BDL, 0, "0.00"));
                }
                sb.Append("</td>");
                sb.Append("<td align=\"center\">");
                sb.Append(sop.getFundType(netValues[i].FundCode.SecurityType));
                sb.Append("</td>");
                sb.Append("<td align=\"center\">");
                sb.Append(sop.getIndexLinkFav(netValues[i].FundCode.Code, ""));
                sb.Append("</td>");
                sb.Append("<td align=\"center\">");
                sb.Append("<a style=\"cursor:pointer;\" onclick=\"delcookie('" + netValues[i].FundCode.Code + "')\" target=\"_self\" onclick=\"return confirm('确认删除？');\">");
                sb.Append("删除</a>");
                sb.Append("</td>");
                sb.Append("</tr>");
            }
            context.Response.Write(sb.ToString());
        }
        else if (!string.IsNullOrEmpty(context.Request.QueryString["ensure"]))
        {
            if (!sop.chkFundCode(context.Request.QueryString["ensure"]))
            {
                context.Response.Write("0");
            }
            else
            {
                context.Response.Write("1");
            }
        }
        context.Response.End();
    }


    /// <summary>
    /// 根据基金代码字符串获取这些基金的基本信息
    /// </summary>
    /// <param name="codeString"></param>
    /// <returns></returns>
    public System.Collections.Generic.List<com.stockstar.baseinfo.datacontract.FundNetValueReport> GetFavFundsNetValueReport(string codeString)
    {
        Comparison<com.stockstar.baseinfo.datacontract.FundNetValueReport> sortFunds = new Comparison<com.stockstar.baseinfo.datacontract.FundNetValueReport>(SortByFundCodeString);
        System.Collections.Generic.List<com.stockstar.baseinfo.datacontract.FundNetValueReport> tmp = FundCanalInterface.GetFavFundsListInfo(codeString);
        tmp.Sort(sortFunds);
        return tmp;
    }
    private int SortByFundCodeString(com.stockstar.baseinfo.datacontract.FundNetValueReport tmp1, com.stockstar.baseinfo.datacontract.FundNetValueReport tmp2)
    {
        return fundcodes.IndexOf(tmp1.FundCode.Code) - fundcodes.IndexOf(tmp2.FundCode.Code);
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}